﻿/**
 * 房间数据模型,管理房間各個屬性,入房間名,大小盲注等.
 * 
 * @author LuoDong
 * @email luo4521@online.net.tw
 * 2010-2-7 9:26
 */
package com.addcn.texas.model
{
	import it.gotoandplay.smartfoxserver.SmartFoxClient;
	import it.gotoandplay.smartfoxserver.SFSEvent;
	
	import com.addcn.fog.model.*;	
	import com.addcn.texas.data.HallData;
	import com.addcn.common.utils.Server;
		
	public class  RoomModel extends Model
	{
		public static const ROOM_DATA_REDY : String = "roomDataRedy";	
		
		private var _server : SmartFoxClient;
		private var _type : int //房间类型
		private var _room_data : Object;  //房間數據
		
		
		public function RoomModel() : void
		{
			_initialize();
		}
		
		private function _initialize() : void
		{
			_room_data = { };
			_server = Server.getInstance();
			_server.addEventListener(SFSEvent.onExtensionResponse, _responseHandler);
		}
		
		/**
		 * 獲取游戲場類別
		 * @return int
		 */
		public function getType() : int
		{
			return this._type;
		}
		
		public function getMaxBinld() : int
		{
			return this._room_data["maxBlind"];
		}
		
		public function getMinBinld() : int
		{
			return this._room_data["minBlind"];
		}
		
		public function getRoomData() : Object
		{
			return this._room_data;
		}
		
		public function setRoomData(r_data : Array) : void
		{			
			this._type = r_data[0];			
			var _data : Object = HallData.getInstance().getData(_type);
			_room_data = _data[r_data[1]];			
			sendNotification (ROOM_DATA_REDY, _room_data);
			var _hall : Object = HallData.getInstance().getData("hallList");
			HallData.getInstance().destroyData();
			HallData.getInstance().setData("hallList", _hall);
		}		
			
		//退出房間
		public function exitRoom() : void
		{
			var _data : Object = { }
			_data.ac = "exitRoom";
			_data.rid = _room_data['id'];
			_server.sendXtMessage(Server.ext(0), "roomAc", _data, SmartFoxClient.XTMSG_TYPE_JSON);			
		}
				
		private function _responseHandler(evt : SFSEvent) : void
		{
			var _data = evt.params.dataObj.dataObj;		
			switch(evt.params.dataObj._cmd) {	
								
			}			
		}
		
		override public function destroy():void 
		{	
			_server.removeEventListener(SFSEvent.onExtensionResponse, _responseHandler);
			_room_data = null;
		}	
	}
	
}
